package ruoyi.example.client;

import openapi.client.sdk.OpenApiClientBuilder;
import openapi.sdk.common.enums.AsymmetricCryEnum;
import openapi.sdk.common.enums.CryModeEnum;
import openapi.sdk.common.enums.SymmetricCryEnum;
import openapi.sdk.common.model.OutParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 方式一
 */
@Component
public class UserApiTest {
    @Value("${keys.local.rsa.privateKey}")
    private String privateKey;

    @Value("${keys.remote.rsa.publicKey}")
    private String remotePublicKey;

    String baseUrl = "http://localhost:8080";

    String callerId = "001";

    protected Logger logger = LoggerFactory.getLogger(UserApiTest.class);

    /**
     * 定义OpenApiClient
     */
    openapi.client.sdk.OpenApiClient apiClient = null;

    @PostConstruct
    public void init() {
        apiClient = new OpenApiClientBuilder(baseUrl, privateKey, remotePublicKey, callerId, "userApi")
                .asymmetricCry(AsymmetricCryEnum.RSA)
                .retDecrypt(true)
                .cryModeEnum(CryModeEnum.SYMMETRIC_CRY)
                .symmetricCry(SymmetricCryEnum.AES)
                .enableCompress(false)
                .build();
    }

    public void getUserById() {
        OutParams outParams = apiClient.callOpenApi("getUserById", 10001L);
        logger.info("返回值test1：" + outParams);
    }
}
